package com.dmcloud.dm.auth.config;

import com.dmcloud.common.constant.SecurityConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@ConditionalOnProperty(prefix = "dmCloud.security.oauth2", name = "storeType", havingValue = "jwt", matchIfMissing = true)
@Configuration
public class JwtTokenConfig {

    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    /**
     * 生成jwt
     *
     * @return
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        //签名用于后面服务校验签名
        accessTokenConverter.setSigningKey(SecurityConstants.JWT_SIGN_KEY);
        return accessTokenConverter;

    }

}
